package site.openapi.sdk.demo.smartdoc.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import site.openapi.sdk.demo.smartdoc.model.Employee;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author rick
 * @since 1.0.0
 * <p/>
 * <p>
 * <p/>
 *
 * <h4>Record list</h4>
 * 2025/11/5 14:22 init </br>
 */
@RestController
@RequestMapping("/demo")
public class DemoController {
    public static final Map<Long, Employee> employees = new HashMap<>();

    /**
     * @param id 雇员唯一ID
     * @return 雇员信息
     * @apiNote 查询雇员信息
     */
    @GetMapping("employee/{id}")
    public ResponseEntity<Employee> getEmployee(@PathVariable("id") Long id) {
        return ResponseEntity.ok(employees.get(id));
    }

    /**
     * @param employee 雇员实体信息 site.openapi.sdk.demo.smartdoc.model.Employee
     * @return 添加雇员结果
     * @apiNote 添加新的雇员信息
     */
    @PostMapping("employee")
    public ResponseEntity<Void> addEmployee(@RequestBody Employee employee) {
        Objects.requireNonNull(employee);
        Objects.requireNonNull(employee.getId());
        employees.put(employee.getId(), employee);
        return ResponseEntity.ok().build();
    }
}
